#include "lasercameracontrolinsview.h"
#include "ui_lasercameracontrolinsview.h"

LaserCameraControlInsView::LaserCameraControlInsView(int styleIdIn, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::LaserCameraControlInsView)
{
    ui->setupUi(this);
    setGeometry(5,50,451,544);
    initialDisplayStyle(styleIdIn);

}

LaserCameraControlInsView::~LaserCameraControlInsView()
{
    delete ui;
}


void LaserCameraControlInsView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        ui->save_Btn->setGeometry(360,350,70,40);
        break;
    default:
        break;
    }
}


void LaserCameraControlInsView::getInput(LaserCameraCtrlInstruction &instructionParaOut)
{
    instructionParaOut.noteStr=ui->note_lineEdit->text();

    if(ui->radioButton_laserOn->isChecked())
    {
        instructionParaOut.isOn=true;
    }
    else
    {
        instructionParaOut.isOn=false;
    }
    instructionParaOut.jobIndex=ui->lineEdit_jobIndex->text().toInt();

}


void LaserCameraControlInsView::updateView()
{
    if(instructionPara.isOn)
    {
        ui->radioButton_laserOn->setChecked(true);
        ui->radioButton_laserOff->setChecked(false);
    }
    else
    {
        ui->radioButton_laserOn->setChecked(false);
        ui->radioButton_laserOff->setChecked(true);
    }
    ui->lineEdit_jobIndex->setText(QString::number(instructionPara.jobIndex));
    ui->note_lineEdit->setText(instructionPara.noteStr);
}

void LaserCameraControlInsView::changeLanguage(int language)
{
   //TODO
}


void LaserCameraControlInsView::finishEditInstruction(LaserCameraCtrlInstruction instructionParaIn,QString &instructionStrOut)
{
    instructionStrOut.clear();
    instructionStrOut="LASERCAMERA_CTRL ";
    if(instructionParaIn.isOn)
    {
        instructionStrOut+="ON ";
    }
    else
    {
        instructionStrOut+="OFF ";
    }
    instructionStrOut+="JOB[";
    instructionStrOut+=QString::number(instructionParaIn.jobIndex)+"]";

    instructionStrOut+=";//"+instructionParaIn.noteStr;

}



void LaserCameraControlInsView::on_clearNote_Btn_clicked()
{
    ui->note_lineEdit->setText("");
}

void LaserCameraControlInsView::on_save_Btn_clicked()
{
    getInput(instructionPara);
    finishEditInstruction(instructionPara,instructionStr);
//    emit finishEditInstructionSignal();
    emit saveInstructionSignal(instructionStr);
}
